if (!app.user) {app.redirect('/admin/login.php')}
jQuery(function() {

	var tr = $('#product-list tr:first').clone();

	function getProductList() {
		var serverReturn = _get('/app/index.php?d=admin&c=product&m=get_product_list');
		return serverReturn.product_list;
	}

	function generateProductLi(product) {
		var liClone = tr.clone();
		liClone.attr('product-id', product['product_id']);
		liClone.find('[name="order"] span').html(product['product_order']);
		liClone.find('[name="name"] span').html(product['product_name']);
		liClone.find('[name="vote_count"] span span').html(product['product_vote_count']);
		liClone.find('[name="vote_count"] a').attr('href', 'product_vote.php?id='+product['product_id']);
		liClone.find('[name="share_count"] span span').html(product['product_share_count']);
		liClone.find('[name="share_count"] a').attr('href', 'product_share.php?id='+product['product_id']);
		liClone.find('[name="action"] a').attr('href', 'product_edit.php#'+product['product_id']);
		if (product['state'] == 'end_sell') {
			// liClone.addClass('disabled');
		} else {
			// liClone.removeClass('disabled');
		}
		return liClone;
	}

	updateProductList();
	function updateProductList() {
		$('#product-list').empty();
		var products = getProductList();
		var vote_total_count = 0;
		var share_total_count = 0;
		for (var i in products) {
			var product = products[i];
			vote_total_count += parseInt(product['product_vote_count']);
			share_total_count += parseInt(product['product_share_count']);
			$('#product-list').append( generateProductLi(product) );
		}
		$('table thead .tb-vote-count').html('投票数('+vote_total_count+')');
		$('table thead .tb-share-count').html('评论数('+share_total_count+')');
	}


})